#ifndef _Devices6988_H_
#define _Devices6988_H_

#include "qmp6989.h"

#define IIC_6989_IC_ADDR            (0x6C << 1)

#define QMP6989_REG_RESET           0x00
#define QMP6989_REG_PID             0x01
#define QMP6989_REG_STATUS          0x02
#define QMP6989_REG_PRESSURE        0x06
#define QMP6989_REG_TEMPERATURE     0x09
#define QMP6989_REG_CMD             0x30
#define QMP6989_REG_CONFIG1         0xA5
#define QMP6989_REG_CONFIG2         0xA6
#define QMP6989_REG_CONFIG3         0xA7
#define QMP6989_REG_CALIB00         0xAA

#define QMP6989_CALIBRATION_COUNT   18


// typedef enum {
//   QMP6989_P_OSR_256 = 0x04,
//   QMP6989_P_OSR_512 = 0x05,
//   QMP6989_P_OSR_1024 = 0x00,
//   QMP6989_P_OSR_2048 = 0x01,
//   QMP6989_P_OSR_4096 = 0x02,
//   QMP6989_P_OSR_8192 = 0x03,
//   QMP6989_P_OSR_16384 = 0x06,
//   QMP6989_P_OSR_32768 = 0x07,
// } QMP6989_P_OSR_Type;

// typedef enum {
//   QMP6989_T_OSR_256 = 0x04,
//   QMP6989_T_OSR_512 = 0x05,
//   QMP6989_T_OSR_1024 = 0x00,
//   QMP6989_T_OSR_2048 = 0x01,
//   QMP6989_T_OSR_4096 = 0x02,
//   QMP6989_T_OSR_8192 = 0x03,
//   QMP6989_T_OSR_16384 = 0x06,
//   QMP6989_T_OSR_32768 = 0x07,
// } QMP6989_T_OSR_Type;



/* PID */
#define QMP6989_PID__REG		QMP6989_REG_PID
/* Soft Rest bit */
#define QMP6989_RST__REG		QMP6989_REG_RESET
#define QMP6989_RST__MSK		0x24
#define QMP6989_RST__POS		0
/* DRDY bit */
#define QMP6989_DRDY__REG	QMP6989_REG_STATUS
#define QMP6989_DRDY__MSK	0x01
#define QMP6989_DRDY__POS	0
/* P OSR bits */
#define QMP6989_P_OSR__REG       QMP6989_REG_CONFIG2
#define QMP6989_P_OSR__MSK       0x07
#define QMP6989_P_OSR__POS       0
/* T OSR bits */
#define QMP6989_T_OSR__REG       QMP6989_REG_CONFIG3
#define QMP6989_T_OSR__MSK       0x07
#define QMP6989_T_OSR__POS       0



#define QMP6989_GET_BITSLICE(regvar, bitname)   \
  ((regvar & bitname##__MSK) >> bitname##__POS)

#define QMP6989_SET_BITSLICE(regvar, bitname, val)  \
  ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))


typedef struct{
    float calibration[QMP6989_CALIBRATION_COUNT / 2];
    float temperatureC;
    float temperatureF;
    float pressure;
    uint8_t pid;
}QMP6989Type;



int8_t c6988Init(void);
int8_t c6988SoftReset(void);
int8_t c6988StatusRead(void);
int8_t c6988CalibrationGet(void);
float f6988ReadTemperature(void);
int32_t i6988ReadPressure(void);


int8_t qmp6989_set_PP_OSR(QMP6989_P_OSR_Type osrP);
int8_t qmp6989_set_TT_OSR(QMP6989_T_OSR_Type osrT);

#endif
